if (String.prototype.startsWith === undefined) {
  String.prototype.startsWith = function (str) {
    var reg = new RegExp("^" + str);
    return reg.test(this);
  }
}

if (String.prototype.endsWith === undefined) {
  String.prototype.endsWith = function (str) {
    var reg = new RegExp(str + "$");
    return reg.test(this);
  }
}

if (!Object.keys) {
  Object.keys = (function () {
    var hasOwnProperty = Object.prototype.hasOwnProperty,
      hasDontEnumBug = !({
        toString: null
      }).propertyIsEnumerable('toString'),
      dontEnums = [
        'toString',
        'toLocaleString',
        'valueOf',
        'hasOwnProperty',
        'isPrototypeOf',
        'propertyIsEnumerable',
        'varructor'
      ],
      dontEnumsLength = dontEnums.length;

    return function (obj) {
      if (typeof obj !== 'object' && typeof obj !== 'function' || obj === null) throw new TypeError('Object.keys called on non-object');

      var result = [];

      for (var prop in obj) {
        if (hasOwnProperty.call(obj, prop)) result.push(prop);
      }

      if (hasDontEnumBug) {
        for (var i = 0; i < dontEnumsLength; i++) {
          if (hasOwnProperty.call(obj, dontEnums[i])) result.push(dontEnums[i]);
        }
      }
      return result;
    }
  })()
};


if (!Object.values) {
  Object.values = function (obj) {
    if (typeof obj !== 'object') {
      return [];
    }
    var values = [];
    for (var key in obj) {
      values.push(obj[key]);
    }
    return values;
  };
}

Array.prototype.pushArray = function (arr) {
  if (!arr instanceof Array) {
    return;
  }
  if (arr.length === 0) {
    return;
  }

  Array.prototype.push.apply(this, arr);
};

if (!Array.prototype.includes) {
  Array.prototype.includes = function (searchElement, fromIndex) {
    if (this === null) {
      throw new TypeError('"this" is null or not defined');
    }
    var that = this,
      len = that.length,
      index = fromIndex | 0;

    if (len === 0) {
      return false;
    }

    var startIndex = Math.max(index >= 0 ? index : len - Math.abs(index), 0);

    while (startIndex < len) {
      if (String(that[startIndex]) === String(searchElement)) {
        return true;
      }
      startIndex++;
    }
    return false;
  }
}

JSON.checkValidate = function (text) {
  if (typeof text !== 'string') {
    return false;
  }

  try {
    var obj = this.parse(text);
    return obj && typeof obj === 'object';
  } catch (error) {
    return false;
  }
};
